/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.edu.udistrital.conce.presentacion.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import org.apache.commons.lang.StringUtils;

/**
 *
 * @author timotheos
 */
public class TimeOnlyConverter implements Converter {

    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        return value;
    }

    /**
     * Strips of the date part from a full date string and formats it
     * according to the Falabella standards e.g 19112009143023 ==> 12:30
     * @param arg0
     * @param arg1
     * @param value
     * @return
     */
    public String getAsString(FacesContext arg0, UIComponent arg1, Object value) {
        String time = "";
        if ( value==null ){
            return time;
        }
        if ((time = (String) value).length() > 13 && !StringUtils.isEmpty(time)) {
            // Strip off the date part
            time = time.substring(8);
            // Format the time accordingly
            time = time.substring(0, 2) + ":" + time.substring(2, 4);
        }

        return time;
    }
}
